package com.ta.gulimall.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ta.gulimall.member.view.vo.AddressFareVo;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ta.gulimall.common.utils.system.PageUtils;
import com.ta.gulimall.common.utils.system.Query;

import com.ta.gulimall.member.dao.MemberReceiveAddressDao;
import com.ta.gulimall.member.view.entity.MemberReceiveAddressEntity;
import com.ta.gulimall.member.service.MemberReceiveAddressService;


@Service("memberReceiveAddressService")
public class MemberReceiveAddressServiceImpl extends ServiceImpl<MemberReceiveAddressDao, MemberReceiveAddressEntity> implements MemberReceiveAddressService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberReceiveAddressEntity> page = this.page(
                new Query<MemberReceiveAddressEntity>().getPage(params),
                new QueryWrapper<MemberReceiveAddressEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<MemberReceiveAddressEntity> deliveryAddress(Long userId) {
        LambdaQueryWrapper<MemberReceiveAddressEntity> wrapper = new LambdaQueryWrapper<MemberReceiveAddressEntity>()
                .eq(MemberReceiveAddressEntity::getMemberId, userId);

        return list(wrapper);
    }

    @Override
    public AddressFareVo deliveryAddressById(Long id) {
        LambdaQueryWrapper<MemberReceiveAddressEntity> wrapper = new LambdaQueryWrapper<MemberReceiveAddressEntity>()
                .eq(MemberReceiveAddressEntity::getId, id);

        MemberReceiveAddressEntity entity = getOne(wrapper);
        BigDecimal decimal = new BigDecimal("10");

        AddressFareVo build = AddressFareVo.builder()
                .addressVo(entity)
                .fare(decimal)
                .build();
        return build;
    }

}